
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

using Swaf.BizObj;
using Swaf.Container;

namespace Swaf.Gui
{
	[Serializable]
	public class BizProcOfflineState
	{
		protected INameAddressSupport m_state;
		//protected Dictionary<string, ChildWidgetInfo> m_childWidgets;
		protected Dictionary<string, List<ParentBizProcInfo>> m_parentBizProcInfos;

		public string Id;
		public string FactoryName;
		public bool IsSetToProcessLast = false;
		public IBizObj InProgressAddBizObj = null;

		public BizProcOfflineState(string id)
		{
			Id = id;
		}

		public void processOfflineState(XmlElement offlineStateInfo)
		{
			XmlElement state = offlineStateInfo.SelectSingleNode("State") as XmlElement;
			if (state != null)
			{
				m_state = new FlexiMap();
				foreach (XmlAttribute a in state.Attributes)
					m_state.put(a.Name, a.Value);
			}
			XmlNodeList pbizProcs = offlineStateInfo.SelectNodes("ParentBizProc");
			if (pbizProcs.Count > 0)
				m_parentBizProcInfos = new Dictionary<string, List<ParentBizProcInfo>>();
			int c = 0;
			foreach (XmlElement procEl in pbizProcs)
				addParentBizProcInfo(new ParentBizProcInfo(procEl, ("gen" + c++)));

			XmlElement filterSortEl = offlineStateInfo.SelectSingleNode("FilterSortOptions") as XmlElement;
			if (filterSortEl != null)
			{
				IBizObj filterSort = Application.currentApp.bizObjMgr.createSource(SourceType.BasicSource, filterSortEl.OuterXml).getList("FilterSortOptions", null)[0];
				State.put("fsCritera", filterSort);
			}
		}

		public void addParentBizProcInfo(ParentBizProcInfo pinfo)
		{
			if(m_parentBizProcInfos == null)
				m_parentBizProcInfos = new Dictionary<string, List<ParentBizProcInfo>>();

			if (!m_parentBizProcInfos.ContainsKey(pinfo.DataId))
				m_parentBizProcInfos[pinfo.DataId] = new List<ParentBizProcInfo>();
			m_parentBizProcInfos[pinfo.DataId].Add(pinfo);
		}

		public INameAddressSupport State
		{
			get
			{
				if (m_state == null)
					m_state = new FlexiMap();
				return m_state;
			}
		}

		public Dictionary<string, List<ParentBizProcInfo>> ParentBizProcs
		{
			get
			{
				if (m_parentBizProcInfos == null)
					m_parentBizProcInfos = new Dictionary<string, List<ParentBizProcInfo>>();
				return m_parentBizProcInfos;
			}
		}
	
	}
}
